from selenium.webdriver.common.by import By
from pages.base_page import Page


class ChatButtonPage(Page):
    # Type
    ele_type_adaptive_button = (By.XPATH, u'//button[@value="adaptive"]')
    ele_type_image_button = (By.XPATH, u'//button[@value="adaptive"]')
    ele_type_text_link_button = (By.XPATH, u'//button[@value="adaptive"]')

    ele_title = (By.ID, u'page-chatButton-title')
    ele_offset_from_right = (By.ID, u'form-chatButton-numberInput-adaptiveButtonRightOffset')
    ele_offset_from_bottom = (By.ID, u'form-chatButton-numberInput-adaptiveButtonBottomOffset')
    # Mobile View elements
    ele_offset_from_right_mobile = (By.ID, u'form-chatButton-numberInput-adaptiveButtonRightOffsetOnMobile')
    ele_offset_from_bottom_mobile = (By.ID, u'form-chatButton-numberInput-adaptiveButtonBottomOffsetOnMobile')
    ele_save_button = (By.XPATH, u"//button[@data-tag='formButton' and @tabindex='0']")

    ele_error = (By.XPATH, '//div[@role="alert"]')

    def __init__(self, driver, url, site_id):
        Page.__init__(self, driver, url)
        self.site_id = site_id
        self.url = url

    def chat_button_page_eles_check_when_has_chat_button_feature(self):
        # self.find_element(*self.ele_type_adaptive_button).is_enabled()
        # self.find_element(*self.ele_type_image_button).is_enabled()
        # self.find_element(*self.ele_type_text_link_button).is_enabled()
        self.find_element(*self.ele_title).is_enabled()
        # self.click(self.ele_type_adaptive_button)
        self.find_element(*self.ele_offset_from_right).is_enabled()
        self.find_element(*self.ele_offset_from_bottom).is_enabled()
        self.find_element(*self.ele_save_button).is_enabled()

    def chat_button_page_eles_check_when_no_chat_button_feature(self):
        self.find_element(*self.ele_title).is_enabled()
        self.find_element(*self.ele_offset_from_right).is_enabled()
        self.find_element(*self.ele_offset_from_bottom).is_enabled()
        self.find_element(*self.ele_save_button).is_enabled()

    def chat_button_save_when_has_chat_button_feature(self):
        # self.click(self.ele_type_adaptive_button)
        self.input_text(self.ele_offset_from_right, '11')
        self.input_text(self.ele_offset_from_bottom, '11')
        self.input_text(self.ele_offset_from_right_mobile, '11')
        self.input_text(self.ele_offset_from_bottom_mobile, '11')
        self.click(self.ele_save_button)

    def chat_button_save_when_no_chat_button_feature(self):
        self.input_text(self.ele_offset_from_right, '11')
        self.input_text(self.ele_offset_from_bottom, '11')
        self.input_text(self.ele_offset_from_right_mobile, '11')
        self.input_text(self.ele_offset_from_bottom_mobile, '11')
        self.click(self.ele_save_button)
